package mz.behaveas.runner {
	import mz.behaveas.model.spec.SpecRunListener;

	import com.soenkerohde.logging.SOSLoggingTarget;

	import mx.logging.ILogger;
	import mx.logging.Log;

	/**
	 * Implementation of SpecRunListener for output in SOS Max. The Stacktrace will be also traced in the console, because of FDT jump to declaration suport.
	 * 
	 * @author maxim.zaks@gmail.com
	 */
	public class SOSMaxReporter implements SpecRunListener {
		
		private var logger : ILogger;
		private var loggingTarget : SOSLoggingTarget;

		public function SOSMaxReporter() {
			this.logger = Log.getLogger("SpecRunReport");
			this.loggingTarget = new SOSLoggingTarget();
			loggingTarget.includeLevel = true;
			Log.addTarget(loggingTarget);
		}

		
		public function expectationFiredError(getError : Error) : void {
			trace(getError);
		}

		public function expectationDone(report : String) : void {
			logger.info("Report: " + report);
		}

		public function expectationStarted(description : String, index : int) : void {
			logger.info(index + ". Expectation : " + description + " is started");
		}

		public function specIsMalformed(report : String) : void {
			logger.error(report);
		}
		
		public function expectationFailed(expectationIndex : int) : void {
			logger.error(expectationIndex +  ". Expectation has failed");
		}
		
		public function startReport(length : int) : void {
			logger.info("Will check " + length + " specifications");
		}
		
		public function runSpec(description : String, specIndex : int) : void {
			logger.info(specIndex +". Specification : " + description);
		}
		
		public function specReport(report : String) : void {
			logger.info(report);
		}
		
		public function endReport(numberOfExpectations : int, notCorrectExpectations : int, miliSeconds : Number) : void {
			if(notCorrectExpectations>0){
				logger.error("Run " + numberOfExpectations + " expectations. " + notCorrectExpectations + " expectations are not correct. In " + miliSeconds + " ms");
			}else{
				logger.info("Run " + numberOfExpectations + " expectations. In " + miliSeconds + " ms");
			}
		}
	}
}
